//
//  LunJiaMainViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/10.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "TopicListCell.h"
#import "LJMoreTopicCell.h"
#import "LJProfessionalAnswerCell.h"
#import "LJPopularQACell.h"
#import "LJSectionHeaderView.h"
#import "LJSectionSegHeaderView.h"

#import "BA_CommunityInputTextView.h"

#import "TopicListViewController.h"
#import "QASquareViewController.h"
#import "QAPublishViewController.h"
#import "QADetailViewController.h"
#import "TopicSquareViewController.h"
#import "TopicDetailViewController.h"

#import "StoreHotelDetailViewController.h"
#import "StoreDetailViewController.h"


#import "LunJiaMainViewController.h"

@interface LunJiaMainViewController ()<UITableViewDelegate, UITableViewDataSource, BA_BottomInputViewDelegate, UITextViewDelegate>

@property (nonatomic, assign) NSInteger pageSize;
@property (nonatomic, assign) NSInteger pageNum;
@property (nonatomic, strong) NSMutableArray <CommonPostModel*>* dataArray;

@property (nonatomic, assign) NSInteger selectIndex;
@property (nonatomic, strong) BA_CommunityInputTextView *footView;


//商家轮播
@property (nonatomic, strong) NSMutableArray <CommunitySellerModel*>* sellerAnswerList;
//用户提问轮播
@property (nonatomic, strong) NSMutableArray <CommunitySellerModel*>* userQuestionList;
//热门问答
@property (nonatomic, strong) NSMutableArray <CommunitySellerModel*>* hotWeddingList;
//话题列表
@property (nonatomic, strong) NSMutableArray <ProClassificationModel*>* topicList;

@property (nonatomic, strong) dispatch_group_t group;

@property (nonatomic, strong) UITableView *tableview;

@property (nonatomic, strong) UIButton *topBtn;

@property (nonatomic, copy) NSString * remark;
@property (nonatomic, assign) NSInteger selectSegType;


@end

@implementation LunJiaMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIWindow * keyWindow = [UIApplication sharedApplication].keyWindow;
    [keyWindow addSubview:self.footView];
    [self.footView hideView];
    self.topBtn.hidden = YES;

    self.remark = @"2";
    self.selectSegType = LJSectionSegHeaderActionType_hot;
    [self refreshParam];
    [self request_data];
}

- (void)refreshParam {
    self.pageSize = 10;
    self.pageNum = 1;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[IQKeyboardManager sharedManager] setEnableAutoToolbar:NO];
    [[IQKeyboardManager sharedManager] setEnable:NO];

}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[IQKeyboardManager sharedManager] setEnableAutoToolbar:YES];
    [[IQKeyboardManager sharedManager] setEnable:YES];

    [self.footView hideView];
}

- (void)textViewDidEndEditing:(UITextView *)textView {
    
    [self.footView hideView];
}

-(BOOL)textViewShouldEndEditing:(UITextView *)textView {
    
    [self.footView hideView];
    return YES;
}

-(void)BA_BottomInputViewSendTextMessage:(NSString *)message {
    
    [self request_postEvaWithIndex:self.selectIndex AndContent:message];
}

- (void)request_data {
    
    [SVProgressHUD showWithStatus:@"正在请求数据"];
    
    self.group = dispatch_group_create();
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

    dispatch_group_async(self.group, queue, ^{
        dispatch_group_enter(self.group);
        [self request_LunJiaHead];
    });
    
    dispatch_group_async(self.group, queue, ^{
        dispatch_group_enter(self.group);
        [self request_topicList];
    });

    dispatch_group_notify(self.group, dispatch_get_main_queue(), ^{
        
        [SVProgressHUD dismiss];
        [self.tableview.mj_header endRefreshing];
        [self.tableview.mj_footer endRefreshing];
        
        [self.tableview reloadData];

    });
}

- (void)goTop {
    [self.tableview scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView.tag == 10086) {
        self.offset_Y = scrollView.contentOffset.y;
    }
    
    
    if (scrollView.contentOffset.y>TTScreenHeight) {
        self.topBtn.hidden = NO;
    }else{
        self.topBtn.hidden = YES;
    }
}

#pragma mark UITableviewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    switch (section) {
        case LunJiaMainSectionType_gengduohuati:{
            return 1;
        } break;
        case LunJiaMainSectionType_dayi:{
            return 1;
        } break;
        case LunJiaMainSectionType_wenda:{
            return 1;
        } break;
        case LunJiaMainSectionType_jingxuanhuati:{
            return self.dataArray.count;
        } break;
        default:
            break;
    }
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    switch (indexPath.section) {
        case LunJiaMainSectionType_gengduohuati:{
            return [LJMoreTopicCell calculateHeightWith:self.topicList.count];
        } break;
        case LunJiaMainSectionType_dayi:{
            
            if (self.sellerAnswerList.count + self.userQuestionList.count > 0) {
                return [LJProfessionalAnswerCell calculateHeight];
            } else {
                return CGFLOAT_MIN;
            }
        } break;
        case LunJiaMainSectionType_wenda:{
            if (self.hotWeddingList.count > 0) {
                return [LJPopularQACell calculateHeight];
            } else {
                return CGFLOAT_MIN;
            }
        } break;
        case LunJiaMainSectionType_jingxuanhuati:{
            return [TopicListCell calculateHeight];
        } break;
        default:
            break;
    }
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    switch (section) {
        case LunJiaMainSectionType_gengduohuati:{
            return CGFLOAT_MIN;
        } break;
        case LunJiaMainSectionType_dayi:{
            return CGFLOAT_MIN;
        } break;
        case LunJiaMainSectionType_wenda:{
            
            if (self.hotWeddingList.count > 0) {
                return 40;
            } else {
                return CGFLOAT_MIN;
            }
        } break;
        case LunJiaMainSectionType_jingxuanhuati:{
            if (self.dataArray.count > 0) {
                return 70;
            } else {
                return CGFLOAT_MIN;
            }
        } break;
        default:
            break;
    }
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    switch (section) {
        case LunJiaMainSectionType_gengduohuati:{
            return CGFLOAT_MIN;
        } break;
        case LunJiaMainSectionType_dayi:{
            return CGFLOAT_MIN;
        } break;
        case LunJiaMainSectionType_wenda:{
            return CGFLOAT_MIN;
        } break;
        case LunJiaMainSectionType_jingxuanhuati:{
            return CGFLOAT_MIN;
        } break;
        default:
            break;
    }
    return CGFLOAT_MIN;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    WEAKSELF
    switch (section) {
        case LunJiaMainSectionType_gengduohuati:{
            
        } break;
        case LunJiaMainSectionType_dayi:{
            
        } break;
        case LunJiaMainSectionType_wenda:{
            LJSectionHeaderView *sectionHeader =  [[NSBundle mainBundle] loadNibNamed:@"LJSectionHeaderView" owner:nil options:nil].firstObject;
            sectionHeader.sectionTitleLab.text = @"热门问答";
            sectionHeader.subTitleLab.text = @"更多热议";
            
            [sectionHeader addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
                
                QASquareViewController *vc = [[QASquareViewController alloc] init];
                [weakSelf.navigationController pushViewController:vc animated:YES];
                
            }];

            return sectionHeader;
        } break;
        case LunJiaMainSectionType_jingxuanhuati:{
            LJSectionSegHeaderView *sectionHeader =  [[NSBundle mainBundle] loadNibNamed:@"LJSectionSegHeaderView" owner:nil options:nil].firstObject;

            [sectionHeader fillWithType:self.selectSegType];
            
            sectionHeader.LJHeaderViewBlock = ^(LJSectionSegHeaderActionType type) {
              
                switch (type) {
                    case LJSectionSegHeaderActionType_more:{
                        
                        TopicSquareViewController *vc = [[TopicSquareViewController alloc] init];
                        vc.type = TopicSquare_moreTopic;
                        [weakSelf.navigationController pushViewController:vc animated:YES];
                        
                    } break;
                    case LJSectionSegHeaderActionType_hot:{
                        
                        weakSelf.remark = @"2";
                        weakSelf.selectSegType = type;
                        [weakSelf refreshParam];
                        [weakSelf request_data];
                        
                    } break;
                    case LJSectionSegHeaderActionType_new:{
                        weakSelf.selectSegType = type;
                        weakSelf.remark = @"3";
                        [weakSelf refreshParam];
                        [weakSelf request_data];
                        
                    } break;
                    default:
                        break;
                }
            };
            
            return sectionHeader;
        } break;
        default:
            break;
    }
    return [UIView new];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WEAKSELF
    switch (indexPath.section) {
        case LunJiaMainSectionType_gengduohuati:{
            
            LJMoreTopicCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LJMoreTopicCellID"];
            cell.selectionStyle =UITableViewCellSelectionStyleNone;
            
            [cell fillWithArray:self.topicList];
            
            cell.LJMoreTopicCellBlock = ^(NSInteger index) {
              
                if (weakSelf.topicList[index].isOther) {
                    
                    TopicSquareViewController *vc = [[TopicSquareViewController alloc] init];
                    vc.type = TopicSquare_moreTopic;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                    
                } else {
                    TopicListViewController *vc = [[TopicListViewController alloc] init];
                    vc.scId = self.topicList[index].scId;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                }
            };
            return cell;
            
        } break;
        case LunJiaMainSectionType_dayi:{
            
            LJProfessionalAnswerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LJProfessionalAnswerCellID"];
            cell.selectionStyle =UITableViewCellSelectionStyleNone;
            
            [cell fillWith:self.sellerAnswerList And:self.userQuestionList];
            
            cell.LJProfessionalAnswerCellBlock = ^(LJAnswerActionType type, NSInteger index) {
              
                switch (type) {
                    case LJAnswerActionType_store:{
                        
                        //跳店铺详情
                        CommunitySellerModel *model = weakSelf.sellerAnswerList[index];
                        if ([model.classId isEqualToString:Store_Category_Hotel]) {
                            StoreHotelDetailViewController *vc = [[StoreHotelDetailViewController alloc] init];
                            vc.storeId = model.sellerId;
                            [self.navigationController pushViewController:vc animated:YES];
                            
                        } else {
                            StoreDetailViewController *vc = [[StoreDetailViewController alloc] init];
                            vc.storeId = model.sellerId;
                            [self.navigationController pushViewController:vc animated:YES];
                        }
                        
                    } break;
                    case LJAnswerActionType_ask:{
                        
                        QAPublishViewController *vc = [[QAPublishViewController alloc] init];
                        
                        [weakSelf.navigationController pushViewController:vc animated:YES];
                    } break;
                    case LJAnswerActionType_userAsk:{
                        
                        QADetailViewController *vc = [[QADetailViewController alloc] init];
                        vc.mqId = weakSelf.userQuestionList[index].mqId;
                        [weakSelf.navigationController pushViewController:vc animated:YES];
                        
                    } break;
                        
                        
                    default:
                        break;
                }
            };
            
            return cell;
            
        } break;
        case LunJiaMainSectionType_wenda:{
            
            LJPopularQACell *cell = [tableView dequeueReusableCellWithIdentifier:@"LJPopularQACellID"];
            cell.selectionStyle =UITableViewCellSelectionStyleNone;
            
            [cell fillWith:self.hotWeddingList];
            
            cell.LJPopularQACellBlock = ^(NSInteger index) {
              
                QADetailViewController *vc = [[QADetailViewController alloc] init];
                vc.mqId = weakSelf.hotWeddingList[index].mqId;
                [weakSelf.navigationController pushViewController:vc animated:YES];
            };
            
            return cell;
            
        } break;
        case LunJiaMainSectionType_jingxuanhuati:{
            
            TopicListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TopicListCellID"];
            cell.selectionStyle =UITableViewCellSelectionStyleNone;
            
            [cell fillWithModel:self.dataArray[indexPath.row]];
            
            cell.TopicListSectionHeaderBlock = ^(CommunityActionType type) {
              
                switch (type) {
                    case CommunityActionType_Eva:{
                        
                        weakSelf.selectIndex = indexPath.row;
                        [weakSelf.footView showView];
                        [weakSelf.footView.textView becomeFirstResponder];
                        
                    } break;
                    case CommunityActionType_Thumb:{
                        
                        weakSelf.selectIndex = indexPath.row;
                        [weakSelf request_postThumbWithIndex:indexPath.row];
                        
                    } break;
                        
                    default:
                        break;
                }
                
            };
            
            return cell;
            
        } break;
        default: break;
    }
    
    TopicListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TopicListCellID"];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    

    switch (indexPath.section) {
        case LunJiaMainSectionType_gengduohuati:{
        } break;
        case LunJiaMainSectionType_dayi:{
        } break;
        case LunJiaMainSectionType_wenda:{
        } break;
        case LunJiaMainSectionType_jingxuanhuati:{

            TopicDetailViewController *vc = [[TopicDetailViewController alloc] init];
            vc.pid = self.dataArray[indexPath.row].pid;
            [self.navigationController pushViewController:vc animated:YES];
            
        } break;
        default:
            break;
    }
    
}

- (BA_CommunityInputTextView *)footView {
    if (_footView == nil) {
        _footView = [[BA_CommunityInputTextView alloc]init];
        _footView.delegate = self;
        _footView.textView.delegate = self;
    }
    return _footView;
}

- (UIButton *)topBtn {
    
    if (!_topBtn) {
        _topBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_topBtn setImage:[UIImage imageNamed:@"to_top"] forState:UIControlStateNormal];
        [_topBtn addTarget:self action:@selector(goTop) forControlEvents:UIControlEventTouchUpInside];
    }
    return _topBtn;
}

- (UITableView *)tableview {
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.backgroundColor =  UIColorHex(0xf1f1f1);
        
        _tableview.showsHorizontalScrollIndicator = NO;
        _tableview.showsVerticalScrollIndicator = NO;
        
        _tableview.estimatedSectionHeaderHeight = 0;
        _tableview.estimatedSectionFooterHeight = 0;
        _tableview.estimatedRowHeight = 0;
        _tableview.tag = 10086;
        [_tableview registerNib:[UINib nibWithNibName:@"TopicListCell" bundle:nil] forCellReuseIdentifier:@"TopicListCellID"];
        [_tableview registerNib:[UINib nibWithNibName:@"LJMoreTopicCell" bundle:nil] forCellReuseIdentifier:@"LJMoreTopicCellID"];
        [_tableview registerNib:[UINib nibWithNibName:@"LJProfessionalAnswerCell" bundle:nil] forCellReuseIdentifier:@"LJProfessionalAnswerCellID"];
        [_tableview registerNib:[UINib nibWithNibName:@"LJPopularQACell" bundle:nil] forCellReuseIdentifier:@"LJPopularQACellID"];

        [self.view addSubview:_tableview];
        
        [_tableview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
        }];
        
        [self.view addSubview:self.topBtn];
        [self.topBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-6);
            make.bottom.mas_equalTo(- 20);
        }];
        
        WEAKSELF
        _tableview.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
            [weakSelf refreshParam];
            [weakSelf request_data];
        }];
        
        _tableview.mj_footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
            weakSelf.pageNum ++;
            [weakSelf request_data];
        }];
    }
    return _tableview;
}

- (void)request_topicList {
        
    NSMutableDictionary *dic = @{}.mutableCopy;
    NSMutableDictionary *t = @{}.mutableCopy;

    [dic setValue:@(self.pageNum) forKey:@"pageNum"];
    [dic setValue:@(self.pageSize) forKey:@"pageSize"];
    
    [t setValue:[TTUserModel sharedObject].userId forKey:@"replyUserId"];
    
    [t setValue:@"2" forKey:@"isDel"];
    [t setValue:@"2" forKey:@"type"];
    [t setValue:@"3" forKey:@"status"];
    [t setValue:self.remark forKey:@"remark"];
    [dic setValue:t forKey:@"t"];

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_SysPosts];
    
    WEAKSELF

    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {

        if ([data isKindOfClass:[NSDictionary class]]) {

            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                NSDictionary *resultDic = [data valueForKey:@"data"];
                
                if ([resultDic isKindOfClass:[NSDictionary class]]) {
                    
                    NSArray *list = [resultDic valueForKey:@"list"];
                    
                    if ([list isKindOfClass:[NSArray class]]) {
                        
                        if (weakSelf.pageNum == 1) {
                            weakSelf.dataArray = @[].mutableCopy;
                        }
                            
                        for (NSDictionary *dic in list) {
                            CommonPostModel *model = [CommonPostModel modelWithDictionary:dic];
                            model.textHeight = [Utilities getStringHeightWithText:model.content font:[UIFont systemFontOfSize:14] viewWidth:(TTScreenWidth - 54)];
                            [weakSelf.dataArray addObject:model];
                        }
                        
                    } else {
                        
                    }
                }
            }
        }
        dispatch_group_leave(self.group);
    } FailedBlock:^(NSError * _Nonnull error) {
        dispatch_group_leave(self.group);

    }];
}

- (void)request_LunJiaHead {
        
    NSMutableDictionary *dic = @{}.mutableCopy;

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_LunJiaHead];
    
    WEAKSELF

    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        
        if ([data isKindOfClass:[NSDictionary class]]) {

            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                NSDictionary *resultDic = [data valueForKey:@"data"];
                
                NSArray *sellerAnswerList = [resultDic valueForKey:@"sellerAnswerList"];
                NSArray *userQuestionList = [resultDic valueForKey:@"userQuestionList"];
                NSArray *hotWeddingList = [resultDic valueForKey:@"hotWeddingList"];
                NSArray *topicList = [resultDic valueForKey:@"topicList"];
                
                if ([sellerAnswerList isKindOfClass:[NSArray class]]) {
                    weakSelf.sellerAnswerList = @[].mutableCopy;
                    for (int i = 0; i < sellerAnswerList.count; i++) {
                        NSDictionary *dic = sellerAnswerList[i];
                        CommunitySellerModel *model = [CommunitySellerModel modelWithDictionary:dic];
                        model.index = i;
                        [weakSelf.sellerAnswerList addObject:model];
                    }
                }
                
                if ([userQuestionList isKindOfClass:[NSArray class]]) {
                    weakSelf.userQuestionList = @[].mutableCopy;
                    for (int i = 0; i < userQuestionList.count; i++) {
                        NSDictionary *dic = userQuestionList[i];
                        CommunitySellerModel *model = [CommunitySellerModel modelWithDictionary:dic];
                        model.index = i;
                        [weakSelf.userQuestionList addObject:model];
                    }
                }
                
                if ([hotWeddingList isKindOfClass:[NSArray class]]) {
                    weakSelf.hotWeddingList = @[].mutableCopy;
                    for (int i = 0; i < hotWeddingList.count; i++) {
                        NSDictionary *dic = hotWeddingList[i];
                        CommunitySellerModel *model = [CommunitySellerModel modelWithDictionary:dic];
                        model.index = i;
                        [weakSelf.hotWeddingList addObject:model];
                    }
                }
                
                if ([topicList isKindOfClass:[NSArray class]]) {
                    weakSelf.topicList = @[].mutableCopy;
                    for (int i = 0; i < topicList.count; i++) {
                        NSDictionary *dic = topicList[i];
                        ProClassificationModel *model = [ProClassificationModel modelWithDictionary:dic];

                        if (i==0 || i==1 || i==2) {
                            model.isHot = YES;
                        }
                        model.isOther = NO;
                        [weakSelf.topicList addObject:model];
                        
                        //查看更多
                        if (topicList.count > 0 && i== topicList.count-1) {
                            ProClassificationModel *model = [[ProClassificationModel alloc] init];
                            model.parentName = @"查看更多话题";
                            model.isOther = YES;
                            [weakSelf.topicList addObject:model];
                        }
                    }
                }                
            }
        }
        dispatch_group_leave(self.group);
    } FailedBlock:^(NSError * _Nonnull error) {
        dispatch_group_leave(self.group);
    }];
}



- (void)request_postEvaWithIndex:(NSInteger)index AndContent:(NSString *)content {
        
    CommonPostModel *model = self.dataArray[index];
    
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:content forKey:@"content"];

    [dic setValue:model.pid forKey:@"baseId"];
    [dic setValue:@"2" forKey:@"level"];
    [dic setValue:model.source forKey:@"source"];
    [dic setValue:model.userId forKey:@"userId"];
    
    //操作类型（1：评论，2：点赞，3：删除，4：下架，5：取消点赞）必传
    [dic setValue:@"1" forKey:@"mold"];

    //类型（1：谈婚，2：论嫁，3：问答）必传
    [dic setValue:@"2" forKey:@"type"];
    //层级（1,2,3）必传
    [dic setValue:@"2" forKey:@"replySource"];
    [dic setValue:[TTUserModel sharedObject].userId forKey:@"replyUserId"];

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_CommonEva];
    
    WEAKSELF
    [SVProgressHUD showWithStatus:@"正在发布评论"];
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {

        [[TTNoResultManager shareManager] hideNoResultWithView:weakSelf.tableview];
        
        [SVProgressHUD dismiss];
        if ([data isKindOfClass:[NSDictionary class]]) {

            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                weakSelf.footView.textView.text = @"";
                [weakSelf.view endEditing:YES];
                
                [weakSelf request_data];
                
            } else {
                
                [SVProgressHUD showErrorWithStatus:[data valueForKey:@"message"]];
                [SVProgressHUD dismissWithDelay:1];
            }
        }
        
    } FailedBlock:^(NSError * _Nonnull error) {
        [SVProgressHUD dismiss];
    }];
}


- (void)request_postThumbWithIndex:(NSInteger)index {
        
    CommonPostModel *model = self.dataArray[index];

    NSMutableDictionary *dic = @{}.mutableCopy;

    //点赞帖子
    [dic setValue:model.pid forKey:@"baseId"];
    [dic setValue:@"1" forKey:@"level"];
    [dic setValue:model.source forKey:@"source"];
    [dic setValue:model.userId forKey:@"userId"];

    
    //操作类型（1：评论，2：点赞，3：删除，4：下架，5：取消点赞）必传
    if (model.isZan.length > 0) {
        [dic setValue:@"5" forKey:@"mold"];
        [dic setValue:model.isZan forKey:@"otherId"];
    } else {
        [dic setValue:@"2" forKey:@"mold"];
    }

    //类型（1：谈婚，2：论嫁，3：问答）必传
    [dic setValue:@"2" forKey:@"type"];
    //层级（1,2,3）必传
    [dic setValue:@"2" forKey:@"replySource"];
    [dic setValue:[TTUserModel sharedObject].userId forKey:@"replyUserId"];

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_CommonEva];
    
    WEAKSELF
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {

        [[TTNoResultManager shareManager] hideNoResultWithView:weakSelf.tableview];
        
        if ([data isKindOfClass:[NSDictionary class]]) {

            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                
                NSString *isZan = [data valueForKey:@"data"];
                if ([isZan isKindOfClass:[NSString class]]) {
                    
                    model.isZan = isZan;
                    if (isZan.length > 0) {
                        model.likes++;
                    } else {
                        model.likes--;
                    }
                    
                    [weakSelf.tableview reloadData];
                }
            } else {
                
                [SVProgressHUD showErrorWithStatus:[data valueForKey:@"message"]];
                [SVProgressHUD dismissWithDelay:1];
            }
        }
        
    } FailedBlock:^(NSError * _Nonnull error) {

    }];
}

@end
